/**
 *
 * Copyright Pact Lab of H.I.T.
 *
 * Designed and Implemented by Grid Researching Group, 
 * Pact Lab, Harbin
 * 
 * This Project is part of the national 973 Project:
 * Internet Based Virtual Computing Environment
 *
 * http://pact518.hit.edu.cn
 * 
 * Author:       Meteor <meteorlxk@gmail.com> 
 * Copyright:    pact518 
 * Version:      1.0
 * Created:      2009-5-2 
 * LastModified: 2009-5-2
 */
package edu.hit.pact.pgse.crawler;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.zip.DataFormatException;

import edu.hit.pact.pgse.communication.CommUtil;
import edu.hit.pact.pgse.crawler.handler.CrawlerMasterHandler;
import edu.hit.pact.pgse.timer.CrawlerSpeedReportSche;
import edu.hit.pact.pgse.util.Globals;

/**
 * @author meteorlxk
 *
 */
public class CrawlerMainControl {
	
	public static void main(String args[]) throws DataFormatException, IOException {
		System.out.println("");
		System.out.println("--------------------< P A C T   C R A W L E R >--------------------");
		System.out.println("");
		System.out.println("                    Crawler begins to work. ^-^                 ");
		System.out.println("");
		System.out.println("--------------------<   G O O D     L U C K   >--------------------");
		System.out.println("");
		System.out.println("");
		
		/*
		 * load log4j property.
		 */
		Globals.readLog4jProperties();

		/*
		 * Load master node info
		 */
		SocketAddress masterAddress = new InetSocketAddress(Globals.MASTER_ADDRESS_IP, Globals.MASTER_LISTEN_PORT_FOR_CRAWLER);
		CrawlerManager crawlerManager = new CrawlerManager();
		CommUtil communicationUtil = new CommUtil(new CrawlerMasterHandler(crawlerManager));
		communicationUtil.setConnector(masterAddress);
		
		if (Globals.MASTER_GRAPH_OPEN || Globals.MASTER_PLOT_OPEN){
				CrawlerSpeedReportSche speedReportScheduler = new CrawlerSpeedReportSche(crawlerManager);
				speedReportScheduler.scheduleSpeedReportTask();
		}

	}
}
